package com.aegis.gateway.strategy;

import com.aegis.gateway.enums.PermissionTypeHandlerEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author wuweixin
 *
 * @Version 1.0
 * @Descritube
 */
@Component
public class FilterDistributeContext {

    private final Map<PermissionTypeHandlerEnum, FilterDistributeHandler> handlerMap = new HashMap<>();

    @Autowired
    public FilterDistributeContext(List<FilterDistributeHandler> handlers) {
        for (FilterDistributeHandler handler : handlers) {
            for (PermissionTypeHandlerEnum value : PermissionTypeHandlerEnum.values()) {
                if (value.getAClass() == handler.getClass()) {
                    handlerMap.put(value, handler);
                    break;
                }
            }
        }

    }

    public FilterDistributeHandler getHandler(PermissionTypeHandlerEnum type) {
        return handlerMap.get(type);
    }
}
